package site.immonkey.dbtool.datasource;

import java.util.Map;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;

import site.immonkey.dbtool.beans.DataSourceConfig;

public class DbcpDataSourceAdapter extends DataSourceAdapter {
    @Override
    protected DataSource adapter(DataSourceConfig config) {
        BasicDataSource ds = new BasicDataSource();
        ds.setUsername(config.getUsername());
        ds.setPassword(config.getPassword());
        ds.setDriverClassName(config.getDriverClass());
        ds.setUrl(config.getJdbcUrl());
        return ds;
    }

    @Override
    protected DataSource adapter(Map<String, String> config) {
        BasicDataSource ds = new BasicDataSource();
        injectProperty(ds, config);
        return ds;
    }
}